package com.asnike.P.bejeweled{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	public class Jewel extends Sprite{
		
		static internal var WIDTH:Number = 48;
		static internal var HEIGHT:Number = 48;
		
		static internal function GET( $type:int ):Jewel{
			var jewel:Jewel;
			
			jewel = new Jewel;
			jewel.init( $type );
			
			return jewel;
		}
		
		private var _type:int;
		private var _willBeRemove:Boolean;
		
		public function Jewel(){
			super();
			
		}
		private function init( $type:int ):void{
			setType( $type );
			setImage();
		}
		private function setType( $value:int ):void{
			if( isInvalidType( $value ) ){
				throw new RangeError( '$value의 범위는 0~5사이여야 합니다.' );
			}
			
			_type = $value;
		}
		private function isInvalidType( $value:int ):Boolean{
			return ( $value < 0 || $value > 5 );
		}
		private function setImage():void{
			addChild( new Bitmap( Main.resources[_type] ) );
			getChildAt( 0 ).x = getChildAt( 0 ).width*-.5;
			getChildAt( 0 ).y = getChildAt( 0 ).height*-.5;
		}
		
		internal function getType():int{
			return _type;
		}
		
		internal function getWillBeRemove():Boolean{
			return _willBeRemove;
		}
		internal function setWillBeRemove():void{
			_willBeRemove = true;
		}
	}
}